package com.jumper.mydemo.statics;

import java.io.IOException;
import java.util.Arrays;

import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;

public class MetadataDemo {
    public static void run() throws IOException {
        SimpleMetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
		MetadataReader metadataReader = readerFactory.getMetadataReader("com.jumper.mydemo.my.MyBean");

		ClassMetadata classMetadata = metadataReader.getClassMetadata();
		System.out.println("Class Name = " + classMetadata.getClassName());
		System.out.println("Class IsInterface = " + classMetadata.isInterface());
		System.out.println("Class IsAnnotation = " + classMetadata.isAnnotation());
		System.out.println("Class IsAbstract = " + classMetadata.isAbstract());
		System.out.println("Class IsConcreate = " + classMetadata.isConcrete());
		System.out.println("Class IsFinal = " + classMetadata.isFinal());
		System.out.println("Class IsIndependent = " + classMetadata.isIndependent());
		System.out.println("Class HasEnclosingClass = " + classMetadata.hasEnclosingClass());
		System.out.println("Class EnclosingClassName = " + classMetadata.getEnclosingClassName());
		System.out.println("Class HasSuperClass = " + classMetadata.hasSuperClass());
		System.out.println("Class SuperClassName = " + classMetadata.getSuperClassName());
		System.out.println("Class InterfaceNames = " + Arrays.toString(classMetadata.getInterfaceNames()));
		System.out.println("Class MemberClassNames = " + Arrays.toString(classMetadata.getMemberClassNames()));
		System.out.println("Class Annotations: " + metadataReader.getAnnotationMetadata().getAnnotationTypes());
		System.out.println();

		for(MethodMetadata methodMeatadata : metadataReader.getAnnotationMetadata().getAnnotatedMethods("com.jumper.mydemo.my.MyAnnotation")) {
			System.out.println("Method name: " + methodMeatadata.getMethodName());
			System.out.println("Method DeclaringClassName: " + methodMeatadata.getDeclaringClassName());
			System.out.println("Method ReturnTypeName: " + methodMeatadata.getReturnTypeName());
			System.out.println("Method IsAbstract: " + methodMeatadata.isAbstract());
			System.out.println("Method IsStatic: " + methodMeatadata.isStatic());
			System.out.println("Method IsFinal:" + methodMeatadata.isFinal());
			System.out.println("Method IsOverridable:" + methodMeatadata.isOverridable());
			System.out.println();
		}
    }
}
